<?php

namespace mpend\modules\home\models;

use Yii;
use common\helpers\Url;
use common\helpers\ArrayHelper;
use common\logics\ShopProductLogic;
use common\logics\PositionLogic;
use mpend\models\searchs\AssembleProductSearch;

/**
 * 首页默认面板信息
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class HomeDashboardLogic extends \common\logics\DashboardLogic {

    /**
     * @var array 轮播图
     */
    public $broadcast = [];

    /**
     * @var array 导航
     */
    public $navigation = [];

    /**
     * @var array 菜单
     */
    public $notice = [];

    /**
     * @var Position 单图推荐位推荐内容
     */
    public $socrates;

    /**
     * @var 推荐内容
     */
    public $boothstand;

    /**
     * 顶部轮播图
     * @inheritdoc
     */
    protected function setBroadcast() {
        return PositionLogic::current('shop.home.broadcast', []);
    }

    /**
     * 导航
     * @inheritdoc
     */
    protected function setNavigation() {
        return PositionLogic::current('shop.home.navigation', null);
    }

    /**
     * 通知消息
     * @inheritdoc
     */
    protected function setNotice() {
        return [
            'icon' => Url::attach('assets/icons/notice.png'),
            'text' => '优越新版本领衔上线 迎新季正式集结',
            'link' => ''
        ];
    }

    /**
     * 苏格拉底1+2组合获取
     * @inheritdoc
     */
    protected function setSocrates() {
        $left = PositionLogic::current('shop.home.socrate.left');
        $right = PositionLogic::current('shop.home.socrate.right');
        return ArrayHelper::merge($left, $right);
    }

    /**
     * 推荐商品
     * @inheritdoc
     */
    protected function setBoothstand() {
        $adverts = PositionLogic::current('shop.home.advert');
        /* @var $model \mpend\modules\shop\models\AssembleProductSearch */
        $model = new AssembleProductSearch();
        $model->tag = 'recommend';
        $recommend = $model->limitsSearch(6);
        $model->tag = 'hot';
        $hot = $model->limitsSearch(6);
        $model->tag = 'new';
        $new = $model->limitsSearch(6);
        return [
            [
                'advert' => array_shift($adverts),
                'title' => '超值推荐',
                'spread' => null,
                'format' => 'ualf',
                'products' => $recommend,
            ],
            [
                'advert' => array_shift($adverts),
                'title' => '爱生活',
                'spread' => null,
                'format' => 'ualf',
                'products' => $hot,
            ],
            [
                'advert' => array_shift($adverts),
                'title' => '新品专区',
                'spread' => null,
                'format' => 'larf',
                'products' => $new,
            ]
        ];
    }

}
